//
//  HKAssignPoliceViewController.m
//  AQBPolice
//
//  Created by apple on 2017/7/7.
//  Copyright © 2017年 eight. All rights reserved.
//

#import "HKAssignPoliceViewController.h"

@interface HKAssignPoliceViewController ()


@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *poiLabel;
@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;

@end

@implementation HKAssignPoliceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(renewUI) name:@"assignVcRenewUiNotification" object:nil];
    
}

- (IBAction)receiveButtonClicked:(id)sender {
    [MBProgressHUD showSuccess:@"已派给其他警员" toView:self.view];
    [self.view removeFromSuperview];
    
    //4.发送通知，显示收工按钮
    [[NSNotificationCenter defaultCenter] postNotificationName:@"goHomeButtonNotification" object:nil];


}

- (void)renewUI {
    //获取案件详情
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    double distance = [userDefaults doubleForKey:@"distance"];
    NSString *address = [userDefaults objectForKey:@"address"];
    if ([address containsString:@"自治区"]) {
        NSString *shortAddress = [address componentsSeparatedByString:@"自治区"][1];
        address = shortAddress;
    }
    //更新UI
    self.addressLabel.text = [NSString stringWithFormat:@"位置：%@", [userDefaults objectForKey:@"poi"]];
    self.poiLabel.text = [NSString stringWithFormat:@"详情：%@", address];
    
    if (distance > 1000) {
        double currDistance = distance / 1000;
        self.distanceLabel.text = [NSString stringWithFormat:@"距离：%.2lf公里", currDistance];
    }else {
        self.distanceLabel.text = [NSString stringWithFormat:@"距离：%.2lf米", distance];
    }
}


@end
